package com.ruoyi.web.controller.app.controller;

import com.ruoyi.framework.web.exception.base.XResult;
import com.ruoyi.web.controller.app.service.AppCommentService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.annotations.ApiIgnore;

import java.util.Map;

/**
 * @ClassName MyCommentController
 * @Description TODO
 * @Author tyc@yanyu
 * @Date 2018/12/7 0007 11:17
 **/
@RestController
@RequestMapping("/app/myComment")
@Api(tags = "评论管理")
public class AppCommentController {
    @Autowired
    private AppCommentService commentService;

    /**
     * 发表评论
     *
     * @return
     */
    @RequestMapping(value = "addComment", method = RequestMethod.POST)
    @ApiOperation(value = "发表评论", position = 1, notes = "发表评论")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "content", value = "评论内容", required = true, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "dynamicId", value = "被评论的动态id", required = true, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "toMemberId", value = "被评论用户ID", required = false, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "fromMemberId", value = "评论人ID", required = true, dataType = "String", paramType = "query")
    })
    public XResult addComment(String content, Long dynamicId, Long toMemberId, Long fromMemberId) {
        return new XResult("操作成功", commentService.addComment(content,dynamicId,toMemberId,fromMemberId));
    }

    /**
     * 评论列表
     *
     * @return
     */
    @RequestMapping(value = "getCommentList", method = RequestMethod.POST)
    @ApiOperation(value = "评论列表", position = 2, notes = "评论列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNum", value = "第几页", required = true, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "pageSize", value = "每页显示几条数据", required = true, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "dynamicId", value = "动态id", required = true, dataType = "String", paramType = "query")
    })
    public XResult getCommentList(String dynamicId) {

        return new XResult("操作成功", commentService.queryCommentList(dynamicId));
    }

    /**
     * 删除评论信息
     *
     * @return
     */
    @RequestMapping(value = "deleteComments", method = RequestMethod.POST)
    @ApiOperation(value = "删除评论信息", position = 3, notes = "删除评论信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "评论信息id", required = true, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "dynamicId", value = "动态id", required = true, dataType = "String", paramType = "query")
    })
    public XResult deleteComments(String id, String dynamicId) {
        return new XResult("操作成功", commentService.deleteComments(id, dynamicId));
    }


    @RequestMapping(value = "countNum", method = RequestMethod.POST)
    @ApiOperation(value = "统计评论数量", position = 4, notes = "统计评论数量")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "dynamicId", value = "动态id", required = true, dataType = "String", paramType = "query")
    })
    public XResult countNum(String dynamicId) {
        return new XResult("操作成功", commentService.countNum(dynamicId));
    }
}
